<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
include "../../operations/connection_ajax.php";
	if ( !isset($_GET['pages'] ))
		{
	    	$page = 1 ;
		}else{
			$page = $_GET['pages'] ;
	}
	
	if (isset($_REQUEST['searchAll'])) {
		//$_SESSION['searchstring'] = '';
		unset($_SESSION['searchstring']);
	}
	
	if (isset($_SESSION['searchstring'])) {
		$temp_s = $_SESSION['searchstring'];
	}
	else{
		$temp_s = '';
	}
	
	$rows_per_page = 30;
	$page_start = ( $page - 1 ) * $rows_per_page; 
	$page_end = $page * $rows_per_page;
//delete
$idemployee = $_REQUEST['idemployee'];
$status=$_REQUEST['status'];
if($status==1)
	$sqldelete = "UPDATE `employee` SET `State`='0',`EndDate`=NOW() WHERE (`IDEmployee`='$idemployee')";
else
	$sqldelete = "UPDATE `employee` SET `State`='1', `Type_employee`='1' WHERE (`IDEmployee`='$idemployee')";
mysql_query($sqldelete);

$sqlempworking = mysql_query("SELECT e.IDEmployee,e.FullName,DATE_FORMAT(e.Birthday,'%Y-%m-%d') as Birthday,e.UserName,al.SexName,dl.DepartmentName,e.Position,DATE_FORMAT(e.StartDateProbation,'%Y-%m-%d') as StartDateProbation,DATE_FORMAT(e.EndDateProbation,'%Y-%m-%d') as EndDateProbation,GraduateDegree 
							FROM employee e ,department_lang dl, ac_sex_lang al, roles rl 
						   where e.IDDepartment = dl.IDDepartment and dl.LangID = '".$_SESSION['lang']."' 
						   and e.Sex = al.SexID and al.LangID = '".$_SESSION['lang']."'  
						   and e.IDRole= rl.IDRole and e.IDRole != 1 and e.State = 1 AND e.Type_employee=0 ".$temp_s." limit ".$page_start.",".$rows_per_page);

$sqlempworkingPage = mysql_query("SELECT e.IDEmployee FROM employee e ,department_lang dl, ac_sex_lang al, roles rl 
						   where e.IDDepartment = dl.IDDepartment and dl.LangID = '".$_SESSION['lang']."' 
						   and e.Sex = al.SexID and al.LangID = '".$_SESSION['lang']."'  
						   and e.IDRole= rl.IDRole and e.IDRole != 1 and e.State = 1 AND e.Type_employee=0 ".$temp_s);

$number_of_page = ceil ( mysql_num_rows( $sqlempworkingPage ) / $rows_per_page );

				$i =0;
				 while ($row=mysql_fetch_array($sqlempworking)){ 
				 	$i++ ;?>
					<tr>
					<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col"><?php echo $i;?></td>
					<td class="rf-dt-c" style="font-size: 12px;text-align: left ;" scope="col"><a href="employeemanager.php?content=admin/employeemanagement/content-edit-trying.php&id=<?=$row[IDEmployee]?>" ><?php echo $row[FullName];?></a></td>
					<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col"><?php echo $row[Birthday];?></td>
					<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col"><a href="employeemanager.php?content=admin/employeemanagement/content-edit-trying.php&id=<?=$row[IDEmployee]?>" ><?php echo $row[UserName]?></a></td>
					<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col"><?php echo $row[DepartmentName]?></td>
					<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col"><?php echo $row[StartDateProbation]?></td>
					<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col"><?php echo $row[EndDateProbation]?></td>
					<td class="rf-dt-c" style="font-size: 12px;text-align: left ;" scope="col"><?php echo $row[GraduateDegree]?></td>
					<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col">
						<a onclick="changeTypeEmployee(<?=$row[IDEmployee]?>,0)" ><img src="images/check.png" title="OK"/></a>
						<a onclick="changeTypeEmployee(<?=$row[IDEmployee]?>,1)" ><img src="images/del.png" title="Fail" style="padding-left: 10px"/></a>
					</td>
					<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col">
						<a href="employeemanager.php?content=admin/employeemanagement/content-edit-trying.php&id=<?=$row[IDEmployee]?>" ><?=$l_edit?></a></td>
					<td class="rf-dt-c" style="font-size: 12px;text-align: center;" scope="col">
						<a href="#" onclick="if(confirm('<?php echo $l_confirm_deleteproject?>')){  onclickDelete('<?=$row[IDEmployee]?>',this); return true;}else{return false;}"><?=$l_delete?></a></td>
					</tr>
				<?php }?>
				
				<tr class="trfoot">
	                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="11">
	                        	<div style="text-align: center; width: 100%">
	                            	<span class="rf-ds">
															
															<?php if ( $number_of_page > 1 ) 
															{ 
																if ($page==1)
																	$p=2;
																else if ($page==$number_of_page)
																	$p=$number_of_page-1;
																else $p=$page;
																if($page!=1){?>
																	<a onclick="paging(1,'')" ><span class='button_next'><?php echo "<<<";?></span> </a>
																	<a onclick="paging(<?=($page-1)?>,'')" ><span class='button_next'><?php echo "<<";?></span> </a>
																<?php  }
																else{
																	echo "<span class='button_next'><<<</span>"; 
																	echo "<span class='button_next'><<</span>";
																}
																for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																		if ($i<=$number_of_page && $i>0)
																		
																			if ($i==$page){
																				echo "<span class='button_next' style='color: #000'><i>".$i."</i></span>"; 
																			}else{
																			?>
																				<a onclick="paging(<?=$i?>,'')" ><span class="button_next">
																				<?php 
																				echo $i;
																				?>
																				</span> </a>
																			<?php 
																			}
																		?>
																	
																<?php 
																		}
																	
																	if($page!=$number_of_page){ ?>
																		<a onclick="paging(<?=($page+1)?>,'')"><span class='button_next'><?php echo ">>";?></span> </a>
																		<a onclick="paging(<?=($number_of_page)?>,'')" ><span class='button_next'><?php echo ">>>";?></span> </a>
																	<?php }
																	else{
																		echo "<span class='button_next'>>></span> ";
																		echo "<span class='button_next'>>>></span> ";
																	}
																}
															
																
																?>
																													
														</span>
														</div>
														</td>
	                    </tr>
	                    
	              <?php mysql_close($connection_ajax);?>